package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2023-11-23  19:46
 */
public class ThreadDemo12 {
    private static boolean isQuit = false;
    public static void main(String[] args) throws InterruptedException {
        Thread  t1 = new Thread(() -> {
            while(!isQuit) {
                System.out.println("线程正在工作！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程工作完毕！");
        });
        t1.start();
        Thread.sleep(3000);
        System.out.println("线程停止工作！");
        isQuit = true;
    }
}
